package com.practice.car.cardataapp.util;

import lombok.Getter;
import lombok.Setter;
import scala.annotation.meta.getter;

import java.util.HashMap;

/**
 * car-data-app project
 *
 * @author FlagDied
 * @date 2020/9/2
 */
public class R extends HashMap<String, Object> {
	private R() {//默认0状态成功
		put("status", 0);
		put("msg", "ok");
	}


	//	工厂获取一个R对象
	public static R create() {
		return new R();
	}

	@Override
	public R put(String id, Object value) {
		super.put(id, value);
		return this;
	}
	//  正常回复，包裹一个正常 HashMap
	public R put(HashMap<String, Object> data) {
		this.putAll( data);
		return this;
	}

	// 错误回复，修改 status=1001
	public R error() {
		this.put("status", 1001);
		return this;
	}

	// 错误回复，修改 status1001，并且附带错误信息
	public R error(String msg) {
		this.put("status", 1001);
		this.put("msg", msg);
		return this;
	}
}
